package lanou.giftsay_01.tools;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by dllo on 16/8/15.
 */
public abstract class BaseFragment extends Fragment {
    protected  Context mContext ;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context ;

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate( setLayout() , container ,false);
    }
    //设置布局
    protected  abstract  int setLayout();

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    protected  abstract  void initView();

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }
    protected  abstract  void  initData();

    protected void goTo(Context from , Class<? extends BaseActivity> to){
        Intent intent = new Intent(from , to);
        mContext.startActivity(intent);
    }
}
